<template>
  <div class="left-chart-1">
    <div class="title cursorPointer">包材损耗情况</div>
    <div class="wrap">
      <div class="item-content" v-if="!noData">
        <div class="item">
          <div class="top">胚</div>
          <div v-if="![undefined, null].includes(itemData.peiWasteQty)" class="bottom">
            <span class="value">
              {{ toFix(itemData.peiWasteQty, 2) }}
              <span class="unit">{{itemData.peiUnit}}</span>
            </span>
            <span class="value">{{ toFix(itemData.peiWasteRatio, 2) }}‰</span>
          </div>
          <div v-else class="no-data">暂无数据</div>
        </div>
        <div class="item">
          <div class="top">纸箱</div>
          <div v-if="![undefined, null].includes(itemData.zhixiangWasteQty)" class="bottom">
            <span class="value">
              {{ toFix(itemData.zhixiangWasteQty, 2) }}
              <span class="unit">{{itemData.zhixiangUnit}}</span>
            </span>
            <span class="value"
              >{{ toFix(itemData.zhixiangWasteRatio, 2) }}‰</span
            >
          </div>
          <div v-else class="no-data">暂无数据</div>
        </div>
        <div class="item">
          <div class="top">盖</div>
          <div v-if="![undefined, null].includes(itemData.gaiWasteQty)" class="bottom">
            <span class="value">
              {{ toFix(itemData.gaiWasteQty, 2) }}
              <span class="unit">{{itemData.gaiUnit}}</span>
            </span>
            <span class="value">{{ toFix(itemData.gaiWasteRatio, 2) }}‰</span>
          </div>
          <div v-else class="no-data">暂无数据</div>
        </div>
        <div class="item">
          <div class="top">标签</div>
          <div v-if="![undefined, null].includes(itemData.biaoqianWasteQty)" class="bottom">
            <span class="value">
              {{ toFix(itemData.biaoqianWasteQty, 2) }}
              <span class="unit">{{itemData.biaoqianUnit}}</span>
            </span>
            <span class="value"
              >{{ toFix(itemData.biaoqianWasteRatio, 2) }}‰</span
            >
          </div>
          <div v-else class="no-data">暂无数据</div>
        </div>
      </div>
      <div v-else class="no-data">暂无数据</div>
    </div>
  </div>
</template>

<script>
import { getOrderWasteInfo } from "@/api/dashboard/blowIrriagtionSpinLineDaily";
export default {
  name: "LeftChart2",
  props: {
    orderItem: {
      type: Object,
      default: null,
    },
  },
  data() {
    return {
      itemData: null,
    };
  },
  computed: {
    noData() {
      return !this.orderItem || !this.itemData;
    },
  },
  methods: {
    async getData() {
      if (!this.orderItem) {
        this.itemData = null;
        return;
      }

      try {
        const param = {
          orderId: this.orderItem.id,
        };
        const res = await getOrderWasteInfo(param);

        this.itemData = res.data || null;
      } catch (error) {
        this.itemData = null;
      }
    },
  },
  watch: {
    orderItem: {
      handler() {
        this.getData();
      },
      immediate: true,
    },
  },
};
</script>

<style lang="less" scoped>
.left-chart-1 {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;

  .wrap {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30px 35px;
  }

  .item-content {
    width: 100%;
    height: 100%;
    flex: 1;
    display: flex;
    flex-flow: wrap;
    justify-content: space-around;
    align-items: center;
    .item {
      width: 42%;
      height: 38%;
      border: 2px solid #cccccc;
      border-radius: 10px;
      padding: 12px 16px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      .bottom {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
      .value {
        font-size: 27px;
        font-weight: 600;
        color: #00ffff;
        .unit {
          font-size: 17px;
        }
      }
    }
  }
}
</style>
